import fs from 'fs'
import axios from 'axios'
import cheerio from 'cheerio'
async function httpRequire() {
  const data = await axios.post('https://www.qmsjmfb.com/erciyuan.php')
  const $ = cheerio.load(data.data)
  const nameArr: string[] = []
  $('li').each((i, el) => {
    nameArr.push($(el).text())
  })
  writeFile(nameArr)
}
// 写入文件
async function writeFile(nameArr: string[]) {
  const text = JSON.stringify({
    names: nameArr,
  })
  fs.writeFile(__dirname + '/names.jsons', text, (err) => {
    if (err) throw new Error(err.toString())
    console.log('names file success')
  })
}

httpRequire()
